/**
 * @file ThreadCond.h
 * @author huangxiaozhu (xiaozhuhuang2014@163.com)
 * @brief  条件变量的封装
 * @version 1.0.0
 * @date 2024-02-26
 * 
 * @copyright Copyright (c) 2024
 * 
 */

#pragma once

#include <mutex>
#include <condition_variable>

class ThreadCond{
public:
    ThreadCond(){}
    virtual ~ThreadCond(){}

public:
    void Wait();                                            // 无限等待

    bool WaitForTimeMS(unsigned int timeOutMS);
    bool WaitForTimeS(unsigned int timeOutS);

    void NotifyOne();
    void NotifyAll();


    /**
     * @brief 同时多次调用此接口，重置用于条件判断的变量由用户在业务流程中控制（ResetForVariable）
     * 
     * @param timeOutMS 
     * @return true 
     * @return false 
     */
    bool WaitForVariable(unsigned int timeOutMS);
    void NotifyForVariable();
    void ResetForVariable();

protected:
    bool m_variable{false};
    
    std::mutex m_cvMutex;
    std::condition_variable m_cond;  

};
